package com.ruoyi.auth;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

/**
 * 默认从 application.yml中获取配置数据
 * 使用 此starter的模块可以实现一个 DbAuthenticationConfigurationProvider ，从数据库中读取配置
 */
@ConditionalOnMissingBean(AuthenticationConfigurationProvider.class)
public class DefaultAuthenticationConfigurationProvider  implements AuthenticationConfigurationProvider {

    private UnifiedAuthenticationProperties properties;

    public DefaultAuthenticationConfigurationProvider(UnifiedAuthenticationProperties properties) {
        this.properties = properties;
    }

    @Override
    public UnifiedAuthenticationSettings getUnifiedAuthenticationSettings() {
        UnifiedAuthenticationSettings settings = new UnifiedAuthenticationSettings();
        settings.setApplicationId(properties.getApplicationId());
        settings.setPrivateKey(properties.getPrivateKey());
        settings.setCharset(properties.getCharset());
        settings.setEncryptionAlgorithm(properties.getEncryptionAlgorithm());
        settings.setVersion(properties.getVersion());

        settings.setBaseUrl(properties.getBaseUrl());
        settings.setLoginPath(properties.getLoginPath());
        settings.setSignPath(properties.getSignPath());

        settings.setExchangeTokenPath(properties.getExchangeTokenPath());
        settings.setNaturalUserPath(properties.getNaturalUserPath());
        settings.setLegalUserPath(properties.getLegalUserPath());

        return settings;
    }
}
